/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.dao;

import com.myapp.model.Documento;
import com.myapp.model.Usuario;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 *
 * @author elio
 */
public class HibernateConfiguracao {
 private static SessionFactory sessionFactory;
    public HibernateConfiguracao() {
    }
    public Session openSession() {
        if (sessionFactory == null) {
            criaSessionFactory();
        }
            return sessionFactory.openSession();
       }

    public void criaSessionFactory() {
            AnnotationConfiguration cfg = new AnnotationConfiguration();
            cfg.addAnnotatedClass(Usuario.class);
            cfg.addAnnotatedClass(Documento.class);
            sessionFactory = cfg.buildSessionFactory();
    }
}
